package com.health.controller;

import com.health.domain.dto.LoginDTO;
import com.health.domain.pojo.User;
import com.health.domain.vo.Result;
import com.health.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ghy
 * @version 1.0
 * @since 2025-06-20 17:01
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 登录接口
     * @param loginDTO 登录请求实体
     * @return 登录成功的Result
     */
    @PostMapping("/login")
    public Result<String> login(@RequestBody LoginDTO loginDTO){
        log.info("{}", loginDTO);
        // 调用业务层去处理登录的逻辑
        User user = userService.login(loginDTO);
        return Result.success(user.getUsername());
    }


}
